class PromiseQueue {
    constructor(options = {}) {
        this.conCurrency = options.conCurrency;
        this.cacheList = [];
        this.count = 0;
    }
    add(fn) {
        // 权重 可以在插入的位置排序
        this.conCurrency.push(fn)
        this.run()
    }

    run() {
        // for (let i = 0; i < array.length; i++) {
            if (!this.cacheList.length || this.count > this.conCurrency) {
                return
            }
            let fn = this.cacheList.shift();
            let promise = fn()
            this.count++
            promise.then(this.complateDone.bind(this)).catch(this.complateDone.bind(this))
        // }
    }

    complateDone(res) {
        this.count--;
        this.run()

    }
}